package com.wc.alorithm_blue_bridge._数学知识.组合数.糊涂人寄信;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/17 19:57
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3441395&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 全错排序：
     * n 和 f[n - 1] 里面任意一个已经错排序的换  (n - 1) * f[n - 1]
     * n 和 1, 2, ..., n - 1 进行互换, 然后剩下的 n - 2进行错拍 也就是 (n - 1) * f[n - 2]
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 25;
    static long[] f = new long[N];
    static int n;

    public static void main(String[] args) {
        f[2] = 1;
        for (int i = 3; i < N; i++) f[i] = (i - 1) * (f[i - 1] + f[i - 2]);

        while (sc.hasNext()) {
            n = sc.nextInt();
            out.println(f[n]);
        }
        out.flush();
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
